<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
	layout:decorator="v2/layout">
  <head>
    <title>欢迎进入管理系统</title>
    <script type="text/javascript" th:inline="javascript">
    	var orgName = [[${session.user.name}]];
    	var labels = [[${labels}]];
        var labelTitle = "";
        if(labels){
            var ls = JSON.parse(labels);
            for(var i=0;i<ls.length;i++){
                labelTitle+= ","+ls[i].name;
            }
		}
    	var id = getParam("id");
        
       	var export_execl = function(){
       		location.href='list-detailApplyExportExecl?id='+id+'&beginAt='+(beginAt==null?'':beginAt)+'&endAt='+(endAt==null?'':endAt);
       	}
       	
       	var updateApply = function(id, verify){
       		var text = "";
       		if(verify=='Pass'){
       			text = "通过？";
       		}else {
       			text = "拒绝？";
       		}
       		$.jjconfirm({text:text,yes:function(){
       			$.ajaxData({url:"list-detailApplyVerify",type:"post",data:{id:id,verify:verify},success:function(){
           			$("#listPage").pageReload();
           		}});
   			}});
       	}
       	var showMedia = function(that, text){
       		var data = eval(text);
       		$.showMedia({data:data});
       	}
       	
       	var updVerifyState = function(id, verifyState){
       		$.ajaxData({url:"list-detailPassWorkVerify",type:"post",data:{id:id,verifyState:verifyState},success:function(){
       			$("#listPage").pageReload();
       		}});
       	}
       	var updRemark = function(id, that){
       		var msg = $(that).val();
       		$.ajaxData({url:"list-detailPassWorkRemark",type:"post",data:{id:id,msg:msg},success:function(){
       			$("#listPage").pageReload();
       		}});
       		
       	}
       	var search = function(){
       		var referenceId = $("input[name='referenceId']").val();
       		var fullName = $("input[name='fullName']").val();
       		var beginAt = $("input[name='beginAt']").val();
       		var endAt = $("input[name='endAt']").val();
       		var member = $("select[name='member']").val();
       		
       		$.pageReload('listPage',{referenceId:referenceId, beginAt:beginAt, endAt:endAt, fullName:fullName,member:member});
       	}
       	var showPageData = function(type, list){
       		$.each(list, function(i,v){
  				v.createdAt = new Date(v.createdAt).Format("yyyy-MM-dd HH:mm");
    			v.passAt = (v.passAt==null)?'--':new Date(v.passAt).Format("yyyy-MM-dd HH:mm");
    			v.uploadAt = (v.uploadAt==null)?'--':new Date(v.uploadAt).Format("yyyy-MM-dd HH:mm");
    			
    			try{
    				v.bsText = JSON.stringify(v.bs);	
        			var applyInfos = JSON.parse(v.applyText);
            		for(var k in applyInfos){
            			v[k] = applyInfos[k];
            		}
            		var urls = [];
            		for(var i=0;i<v.bs.length;i++){
            			var b = v.bs[i];
            			urls[urls.length]=b.url;
            		}
            		v.urls = urls.join(",");
            		if(urls && urls.length>0){
            			v.mediaSize = urls.length;
                		v.mediaUrl1 = urls[0];
            		}
    			}catch(e){}
    			
    		});
       		
       		if(type == 'export'){
       			return;
       		}
  			$.setData({content:list,orgName:orgName,qiniuUrl:qiniuUrl});
       	}
       	var downloadUrlFile = function(urlList, i, call) {
       		if(!urlList[i]){
       			call.apply(null);
       		}
       		var url = urlList[i].url;
       		var fileName = urlList[i].fileName;
            var xhr = new XMLHttpRequest();
            xhr.open('GET', url, true);
            xhr.responseType = 'blob';
            xhr.crossOrigin = 'Anonymous';
            xhr.setRequestHeader('Authorization', 'Basic a2VybWl0Omtlcm1pdA==');
            xhr.onload =function (ev) {
            	if (xhr.status === 200) {
                    var urlObject = window.URL || window.webkitURL || window;
                    var export_blob = new Blob([xhr.response]);
                    var save_link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a')
                    save_link.href = urlObject.createObjectURL(export_blob);
                    var ext = url.match(/\.[^\.]*$/)[0];

                    save_link.download = fileName+ext;
                    $("body").append(save_link)
                    save_link.click();
                    $(save_link).remove();
                }
            	i++;
            	downloadUrlFile(urlList, i, call);
            }
            try{
            	xhr.send();    
            } catch (e) {
            	console.log("下载图片出错url："+url)
            }
            
            
        }
       	var exportWork = function(list, nextCall){
       		if(list){
       			var urlList = [];
       			for(var j=0;j<list.length;j++){
           			var v = list[j];
               		var urls = [];
               		for(var i=0;i<v.bs.length;i++){
               			var b = v.bs[i];
               			var fileName = v.number+"_"+v.fullName+"_"+(i+1);
               			urlList[urlList.length] = {url:b.url,fileName:fileName};
               			
               		}
           		}
       			downloadUrlFile(urlList, 0, function(){
       				nextCall.apply(null);
       			});
       		}
       		return true;
       	}
    	$(function(){
    		setMenu("报名管理-作品板式");
    		$.setData({order: 'mr'})
    		$.ajaxData({url:"list-detailPassStatCount",data:{evaluateId:id},success:function(data){
    			$.setData(data);
    		}})
    		
    		$("#day li[data-day]").click(function(){
    			var day = $(this).data("day");
    			$("#day li").removeClass("active");
    			$(this).addClass("active");
    			$("#listPage").pageReload({verifyState:day});
    		});
    		
    	});
    </script>
    <style>

    </style>
  </head>
  <body>
    <div layout:fragment="content">
    	<div class="info info-full">
    		<div class="stat">
	            <div class="stat-top">
	                <span class="stat-title"><strong>关键数据</strong></span>
	            </div>
	            <div class="stat-content">
	            	<div class="stat-row" id="statCount">
		                <div class="stat-group active">
		                    <div class="stat-group-title">已晋级</div>
		                    <div class="stat-group-count"><strong data-wyx-text="passCount?passCount:0"></strong></div>
		                    <div class="stat-group-day">
		                        <label>今日</label>
		                        <span data-wyx-text="passCount"></span>
		                    </div>
		                </div>
		                <div class="stat-group">
		                    <div class="stat-group-title">待定</div>
		                    <div class="stat-group-count"><strong data-wyx-text="waitCount"></strong></div>
		                    <div class="stat-group-day">
		                        <label>今日</label>
		                        <span data-wyx-text="waitCountDay"></span>
		                    </div>
		                </div>
		                <div class="stat-group">
		                    <div class="stat-group-title">报名人数</div>
		                    <div class="stat-group-count"><strong data-wyx-text="bmCount"></strong></div>
		                    <div class="stat-group-day">
		                        <label>今日</label>
		                        <span data-wyx-text="bmCountDay"></span>
		                    </div>
		                </div>
	                </div>
	            </div>
	
	        </div>
    	</div>
    	
    	<!-- <div class="c_tab">
   			<ul class="c_tab-list" id="day">
   				<li data-day="DPS" class="active">待评审</li>
   				<li data-day="DD">待定</li>
   				<li data-day="JJ">晋级</li>
   				<li data-day="">全部</li>
   			</ul>
    	</div> -->
    	<div class="c_tab">
   			<ul class="c_tab-list">
   				<li onclick="$.setData({order: 'mr'});$.pageReload('listPage',{sort:'id,desc'});" data-wyx-class="{order=='mr'?'active':''}">默认排序</li>
   				<li onclick="$.setData({order: 'zh'});$.pageReload('listPage',{sort:'complexPoint,desc'});" data-wyx-class="{order=='zh'?'active':''}">综合分排序</li>
   			</ul>
    	</div>
    	
    	<div class="search">
    		<div class="search-item">
    			<div class="search-control">
    				<input type="text" placeholder="姓名" class="search-text" name="fullName"/>
    			</div>
    			<div class="search-control">
    				<input type="text" placeholder="渠道ID" class="search-text" name="referenceId"/>
    			</div>
    			<div class="search-control">
    				<input type="text" onfocus="WdatePicker({dateFmt: 'yyyy-MM-dd'})" readonly="readonly" class="search-text" placeholder="首次开始日期" name="beginAt"/>
    			</div>
    			<div class="search-control">
    				<input type="text" onfocus="WdatePicker({dateFmt: 'yyyy-MM-dd'})" readonly="readonly" class="search-text" placeholder="首次结束日期" name="endAt"/>
    			</div>
    			
    			<div class="search-control">
    				<select name="member">
    					<option value="">全部</option>
    					<option value="1">会员</option>
    				</select>
    				
    			</div>
    			<div class="search-control">
    			<div class="search-btn">
    				<span class="search-button" onclick="search();">查询</span>
    			</div>
    			</div>
    		</div>
    	</div>
    	
		<div class="work">	
       		<div class="work-item" data-wyx-for="data:content">
       			<div class="work-item-flex">
       				<div class="work-left">
               			<div class="work-info">
               				<div class="work-info-item">
               					<label class="work-info-label">参赛编号: </label>
               					<span class="work-info-text" data-wyx-text="{data.number}"></span>
               				</div>
               				<div class="work-info-item work-info-full">
               					<label class="work-info-label">姓名: </label>
               					<span class="work-info-text" data-wyx-text="data.fullName"></span>
               				</div>
               				<div class="work-info-item work-info-full">
               					<label class="work-info-label">渠道: </label>
               					<span class="work-info-text" data-wyx-text="data.refName"></span>
               				</div>
               				<div class="work-info-item work-info-full">
               					<label class="work-info-label">首次上传时间:</label>
               					<span class="work-info-text" data-wyx-text="{data.createdAt}"></span>
               				</div>
               				<div class="work-info-item work-info-full">
               					<label class="work-info-label">晋级时间:</label>
               					<span class="work-info-text" data-wyx-text="{data.passAt}"></span>
               				</div>
               				
               				<div class="work-info-item work-info-full">
               					<label class="work-info-label">综合分:</label>
               					<span class="work-info-text" data-wyx-text="{data.complexPoint}"></span>
               				</div>
               				
               				
               				<div class="work-info-item work-info-full">
               					<label class="work-info-label">投票:</label>
               					<span class="work-info-text" data-wyx-text="{data.voteCount}"></span>
               				</div>
               				
               			</div>
               			<div class="work-text">
               				<textarea rows="" cols="" data-wyx-onchange="updRemark({data.evaluateApplyId}, this);" data-wyx-text="{data.remark}"></textarea>
               			</div>
               			<!-- <div class="work-btn">
								<span data-wyx-if="{data.verifyState=='DPS'}" class="work-btn-item" data-wyx-onclick="updVerifyState({data.evaluateApplyId}, 'DD')">选为待定</span>
               					<span data-wyx-if="{data.verifyState=='DPS' || data.verifyState=='DD'}" class="work-btn-item" style="float:right;" data-wyx-onclick="updVerifyState({data.evaluateApplyId}, 'JJ')">选为晋级</span>
								<span data-wyx-if="{data.verifyState=='JJ'}" class="work-btn-item">已晋级</span>
								<span data-wyx-if="{data.verifyState=='DD'}" class="work-btn-item" data-wyx-onclick="updVerifyState({data.evaluateApplyId}, 'DPS')">取消待定</span>
               			</div> -->
       				</div>
       				<div class="work-right">
       					<div class="work-user">
               				<img class="work-user-photo" onerror="javascript:this.src='/img/default2.png'" data-wyx-src="{qiniuUrl}pic_avatar_{data.userNumber}.jpg"/>
               				<div class="work-user-info">
               					<div class="work-user-name" data-wyx-text="data.userName"></div>
               					<div class="work-user-sign" data-wyx-text="data.userNumber"></div>
               				</div>
               			</div>
       					<div class="work-msg" data-wyx-alt="{data.text}" data-wyx-text="data.text"></div>
       					<div class="work-media" data-wyx-onclick="showMedia(this, '{data.bsText}')">
             				<div data-wyx-if="{data.media.type=='VIDEO'}" class="work-media-item">
      							<img onerror="javascript:this.src='/img/default2.png'" class="work-media-img" src="#{data.media.url}#?vframe/jpg/offset/2/imageView2/1"/>
       						</div>
								
      						<div data-wyx-if="{data.media.type=='PIC'}" class="work-media-item">
      							<img onerror="javascript:this.src='/img/default2.png'"  class="work-media-img" data-wyx-src="{data.media.url}"/>
      						</div>
							<span data-wyx-if="{data.media.type=='PIC'}" class="work-media-count" data-wyx-text="{data.bs.length}">个</span>
               			</div>
       					
       				</div>
       			</div>
       		</div>
         	<div data-page="listPage" data-page-action="list-detailPassWorkList" data-page-data="size=4&evaluateId={id}&sort=id,desc" 
         	data-page-csv_title="number(参赛编号),userNumber(用户ID),fullName(参赛姓名),phone(电话),refName(渠道),createdAt(首次上传作品),passAt(晋级时间),itemName(节目),groupName(分组),advName(广告),complexPoint(综合分),voteCount(投票数),remark(备注){labelTitle},blogId(帖子ID),mediaSize(文件数),mediaUrl1(首个文件)" 
         	data-page-csv="用户作品" data-page-csv_apply="$.showPageData('export')" data-page-success="$.showPageData('')" data-page-btns="导出筛选作品" data-page-applys="$.exportWork();"></div>
     	</div>
    </div>
    
    
    
    
  </body>
</html>